package sunyu.demo.storm.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.IRichBolt;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.tuple.Tuple;
import org.slf4j.Logger;
import sunyu.toolkit.core.JsonKit;
import sunyu.toolkit.core.LogKit;

import java.util.Map;

/**
 * @author 孙宇
 */
public class MyBolt1 implements IRichBolt {

    private static final Logger logger = LogKit.getLogger();
    private OutputCollector collector;

    @Override
    public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
        this.collector = collector;
    }

    @Override
    public void execute(Tuple input) {
        ConsumerRecord<String, String> record = (ConsumerRecord<String, String>) input.getValue(0);
        logger.info("{}", JsonKit.toJson(ProtocolKit.toMap(record.value()), false));
        collector.ack(input);
    }

    @Override
    public void cleanup() {
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {
    }

    @Override
    public Map<String, Object> getComponentConfiguration() {
        return null;
    }
}
